package org.NooLab.demoinstances;



 
import org.NooLab.itexx.ITexxFactory;
import org.NooLab.somclients.components.SomClientsFactory;
import org.NooLab.somclients.intf.SomClientsPublicIntf;


 

import processing.core.*;

/*
 * 
 * better: starting as app and opening a secondary window
 * 
 */



public class C1_SCLI_Applet  extends PApplet{

	
	private static final long serialVersionUID = -75401849238245009L; 
	
	
	SomClientsInstanceSC1 scsInstance ;
	 
	PApplet applet;
	
	
	public void setup(){
		 
		applet = this;
		
		try{
			ITexxFactory.init(this.getClass());
		 
			
		} catch (Exception e) {
			System.err.println(e.getMessage());
			return;
		}
		  
		showKeyCommands();
		
		draw();
	 
	}
	
	
	// ................................
	public void draw(){
		background( 128,128, 238);
		
	}
	// ................................
	
	
	public void stop(){
	
		ITexxFactory.stop();
	}
	
	public void keyPressed() {

		
		
		if (key=='s'){
			
			looping = true;
			this.loop() ;
			 
			startEngines() ; // 1= optimizer, 0=simple som (not recommended for most tasks)
			 
		}
		 
		
		if (key=='x'){
			// somInstance. ...
			ITexxFactory.stop();
			
		}
		  
	}
	
	 

	private void showKeyCommands(){

		println();
		println("Welcome to iTexx!\n");
		println("the following key commands are available for minimalistic user-based control...");
		println();
		println("   s  ->  start the listeners and all required modules ");
		println();
		println("   c  ->  open the basic configuration file  ");
		println("   r  ->  show the 'readme' file  ");
		println();
		println("   x  ->  exit");
		println();
		println("------------------------------------------------------------------");
		println();

	}
	

	private void startEngines(){
		println();
		
		scsInstance = new SomClientsInstanceSC1(  ) ;
		
		scsInstance.startInstance() ;
	}
	
	
}

 
class SomClientsInstanceSC1{

	SomClientsPublicIntf scfFactory;
	
	
	public SomClientsInstanceSC1(){
		
	}
	
	
	
	public void startInstance() {
	 
		scfFactory = SomClientsFactory.getInstance(null) ;
		
	}
	
	
	
	
}




